package com.atguigu.mall.member.service.impl;

import cn.hutool.core.util.StrUtil;
import com.atguigu.common.page.PageFactory;
import com.atguigu.common.utils.PageUtils;
import com.atguigu.mall.member.dao.MemberLevelDao;
import com.atguigu.mall.member.entity.MemberLevelEntity;
import com.atguigu.mall.member.service.MemberLevelService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Map;


@Service("memberLevelService")
public class MemberLevelServiceImpl extends ServiceImpl<MemberLevelDao, MemberLevelEntity> implements MemberLevelService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        Page<MemberLevelEntity> page = PageFactory.defaultPage();
        LambdaQueryWrapper<MemberLevelEntity> wrapper = new LambdaQueryWrapper<>();
        String key = (String) params.get("key");
        String sidx = (String) params.get("sidx");
        String order = (String) params.get("order");
        wrapper.like(StrUtil.isNotBlank(key),MemberLevelEntity::getName,key);
        if (StrUtil.isBlank(order)){
            order = "desc";
        }
        boolean isAsc = order.equals("asc");
        wrapper.orderBy(StrUtil.isNotBlank(sidx),isAsc,MemberLevelEntity::getName);
        this.baseMapper.selectPage(page,wrapper);
        return new PageUtils(page);
    }

}